package SortAlgorithmPractice;


import java.util.Arrays;

public  class BubbleSort {

    public static void main(String[] args) {
        int[] arr = {3,1,5,6,9,7,8,10};
        System.out.printf("Sort before : %s\n", Arrays.toString(arr));
        bubbleSort(arr);
        System.out.printf("Sort after : %s\n", Arrays.toString(arr));
    }

    public static void bubbleSort(int[] arr) {

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j <= arr.length - 1; j++){
                if(arr[i] > arr[j]){
                    swap(arr, i, j);
                }
            }

        }
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
